/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                           *
 *                          Copyright (c) 2010                               *
 *                  Alen Stojanov [ ioi.alen@gmail.com ]                     *
 *                Jacobs University Bremen, Bremen, Germany                  *
 *                                                                           *
 *                          All Rights Reserved.                             *
 *                                                                           *
 *    Permission to use, copy, modify and distribute this software and       *
 *    its documentation is hereby granted, provided that both the            *
 *    copyright notice and this permission notice appear in all copies of    *
 *    the software, derivative works or modified versions, and any           *
 *    portions thereof, and that both notices appear in supporting           *
 *    documentation.                                                         *
 *                                                                           *
 *    This code is distributed in the hope that it will be useful, but       *
 *    WITHOUT ANY WARRANTY; without even the implied warranty of             *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS       *
 *    DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER          *
 *    RESULTING FROM THE USE OF THIS SOFTWARE.                               *
 *                                                                           *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <cmath>

#include "tspoint.h"

TSPoint::TSPoint ()
{
	this->type 	= TSPoint::D2;
	this->x 	= 0;
	this->y 	= 0;
	this->z 	= 0;
}

TSPoint::TSPoint (double x, double y)
{
	this->type 	= TSPoint::D2;
	this->x 	= x;
	this->y 	= y;
	this->z 	= 0;
}

TSPoint::TSPoint (double x, double y, double z)
{
	this->type 	= TSPoint::D3;
	this->x 	= x;
	this->y 	= y;
	this->z 	= z;
}

double TSPoint::getX ()
{
	return this->x;
}

double TSPoint::getY ()
{
	return this->y;
}

double TSPoint::getZ ()
{
	return this->z;
}

TSPoint TSPoint::operator+ (const TSPoint& c) const
{
	TSPoint result;
	result.type = this->type;

	result.x = this->x + c.x;
	result.y = this->y + c.y;
	result.z = this->z + c.z;

	return result;
}

TSPoint TSPoint::operator- (const TSPoint& c) const
{
	TSPoint result;
	result.type = this->type;

	result.x = this->x - c.x;
	result.y = this->y - c.y;
	result.z = this->z - c.z;

	return result;
}

TSPoint TSPoint::operator* (double scalar) const
{
	TSPoint result;
	result.type = this->type;

	result.x = this->x * scalar;
	result.y = this->y * scalar;
	result.z = this->z * scalar;

	return result;
}

double TSPoint::distance(TSPoint& point)
{
	return sqrt ( pow(x - point.x, 2) + pow(y - point.y, 2) + pow(z - point.z, 2) );
}

TSPoint::~TSPoint()
{
	// Do nothing
}
